import React, { Component } from "react";
import Child from "./class";
interface IProps {
    name: string;
    count: number;
}

class Parent extends Component<IProps, IProps> {
    constructor(props: IProps) {
        super(props);
        console.log("Parent constructor",props);
        this.state = {
            name: "Parent",
            count: 0
        };
    }
    componentDidMount() {
        console.log("1. 第一个阶段 准备阶段")
    }
    // componentWillReceiveProps(nextProps: IProps) {
    //     console.log("2. 第二个阶段 接收阶段")
    // }
    getDerivedStateFromProps(nextProps: IProps, prevState: IProps) {
        console.log("2. 第二个阶段 准备更新组件阶段 ",nextProps, prevState)
        return null
    }
    shouldComponentUpdate(nextProps: IProps, nextState: IProps) {
        console.log("3. 第三个阶段 是否更新组件阶段",nextProps, nextState)
        return true
    }
    getSnapashotBeforeUpdate(prevProps: IProps, prevState: IProps) {
        console.log("4. 第四个阶段 获取快照阶段",prevProps, prevState)
        return null
    }
    componentDidUpdate(prevProps: IProps, prevState: IProps, snapshot: null) {
        console.log("5. 第五个阶段 更新完成阶段",prevProps, prevState, snapshot)
    }
    componentWillUnmount() {

    }

    incrementCount = () => {
        this.setState({...this.state, count: this.state.count + 1 });
    }
    render() {
        return (
            <div>
                <h1>Hello, {this.state.name}!</h1>
                <Child name={this.state.name} count={this.state.count} onIncrement={this.incrementCount} onEmitFater={this.emitFather} />
            </div>
        );
    }
    emitFather =(value)=>{
        console.log(value);
    }
}

export default Parent;